package chapter03

/**
 * @program lu-scala01
 * @description: 构造器
 * @author: zhanglu
 * @create: 2022-03-10 11:39:00
 */
object C05_Constructor {

  def main(args: Array[String]): Unit = {
    val student01 = new Student01
    student01.student01

    val student02 = new Student01("lu")

    val student03 = new Student01("lu",18)
  }

}

class Student01 {

  var name: String = _
  var age: Int = _

  println("1.主构造方法被调用")

  def this(name: String) {
    this()  //直接调用主构造器
    println("2.辅助构造方法1被调用")
    this.name = name
    println(s"name ${name} age ${age}")
  }

  def this(name: String, age: Int) {
    this(name)  //直接调用主构造器
    println("3.辅助构造方法2被调用")
    this.age = age
    println(s"name ${name} age ${age}")
  }

  def student01: Unit ={
    println("一般方法被调用")
  }

}
